<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>

<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport"
		content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<title>添加图片</title>
	<link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
	<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
	<link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
</head>
<!--/meta 作为公共模版分离出去-->

<body>
	<article class="cl pd-20">
		<div class=" col-xs-12 col-sm-12 col-md-8">
			<form action="" class="form form-horizontal" id="form-upload" enctype="multipart/form-data">
				<div class="row cl  mt-20">
					<label class="form-label col-xs-3 col-sm-3">
					</label>
					<div class="formControls col-xs-4 col-sm-4">
						<input type="file" name="upload_file" class="input-text" id="upload_file">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-3 col-sm-3">
						是否生成缩略图
					</label>
					<div class="formControls col-xs-4 col-sm-4">
						<input type="checkbox" name="isthumb" id="isthumb" value="1">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-3 col-sm-3">
						是否上传至当前目录
					</label>
					<div class="formControls col-xs-4 col-sm-4">
						<input type="checkbox" name="activepath" id="activepath" value="">
					</div>
				</div>
			</form>
		</div>
		<div class="row cl mt-20">
			<div class="formControls col-xs-2 col-sm-2">
				<a href="javascript:;" class="btn btn-primary radius" onClick="uploadImg()">
					上传</a>
			</div>
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input class="btn btn-primary radius" type="button" id="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</article>

	<!--_footer 作为公共模版分离出去-->
	<script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
	<script type="text/javascript" src="../static/h-ui/js/H-ui.js"></script>
	<script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.page.js"></script>
	<!--/_footer /作为公共模版分离出去-->

	<script type="text/javascript" src="../static/js/admin.js?123"></script>

	<!--请在下方写此页面业务相关的脚本-->
	<script type="text/javascript" src="../lib/jquery.validation/1.14.0/jquery.validate.js"></script>
	<script type="text/javascript" src="../lib/jquery.validation/1.14.0/validate-methods.js"></script>
	<script type="text/javascript" src="../lib/jquery.validation/1.14.0/messages_zh.js"></script>
	<script type="text/javascript">
        var activepath = ""
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == "activepath") {
                activepath = pair[1];
            }
		}
		if (activepath=="") {
			activepath="/";
		}
	
		console.log(activepath);
		$("#activepath").val(activepath);

		$("#button").on('click', function () {
			uploadImg();
		});


		function uploadImg() {
			if ($("#upload_file").val() == '') {
				layer.msg("请选择要上传的文件", {
					icon: 6,
					time: 1000
				});
				return false;
			} else {
				var formData = new FormData($("#form-upload")[0]);
				//ajax上传
				$.ajax({
					url: '/ajax/file_manager/uploadimg',
					type: 'POST',
					async: true,
					cache: false,
					data: formData,
					processData: false,
					contentType: false,
					dataType: "json",
					beforeSend: function (request) {
						request.setRequestHeader("authStr", window.localStorage.getItem(
							"userId") + "-" + window.localStorage.getItem("token"));
					},
					success: function (data) {
						// console.log(data);
						if (data.success == true) {
							layer.msg(data.msg+"文件路径:"+data.data.picname, {
								icon: 1,
								time: 1000
							}, function () {
								window.parent.location.reload();
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							});
						} else {
							layer.msg(data.msg);
							return false;
						}
						// uploading = false;
					}
				});
			}
		}
	</script>
	<!--/请在上方写此页面业务相关的脚本-->
</body>

</html>